//
//  ActivityTableViewCell.m
//  豆瓣电影
//
//  Created by dllo on 16/6/24.
//  Copyright © 2016年 dllo. All rights reserved.
//

#import "ActivityTableViewCell.h"
#import "ActivityModel.h"


#define kWith self.contentView.frame.size.width
#define kHeight self.contentView.frame.size.height

#define GREENSIZE self.greenBackImageView.frame.size
#define WHITESIZE self.whiteBackImageView.frame.size

@interface ActivityTableViewCell()

@property (nonatomic, retain) UIImageView *greenBackImageView;

@property (nonatomic, retain) UIImageView *whiteBackImageView;

@property (nonatomic, retain) UIImageView *backImageView;

@property (nonatomic, retain) UIImageView *timeImageView;

@property (nonatomic, retain) UIImageView *locateImageView;

@property (nonatomic, retain) UIImageView *categoryImageView;

@property (nonatomic, retain) UILabel *title;

@property (nonatomic, retain) UILabel *startTime;

@property (nonatomic, retain) UILabel *endTime;

@property (nonatomic, retain) UILabel *address;

@property (nonatomic, retain) UILabel *category_name;

@property (nonatomic, retain) UILabel *wisher;

@property (nonatomic, retain) UILabel *participant;

@property (nonatomic, retain) UILabel *participant_count;

@property (nonatomic, retain) UILabel *wisher_count;

@property (nonatomic, retain) UILabel *category;

@property (nonatomic, retain) UILabel *line;

@end

@implementation ActivityTableViewCell

-(void)dealloc
{
    [_line release];
    [_category release];
    [_backImageView release];
    [_greenBackImageView release];
    [_whiteBackImageView release];
    [_timeImageView release];
    [_locateImageView release];
    [_categoryImageView release];
    [_startTime release];
    [_endTime release];
    [_address release];
    [_category_name release];
    [_wisher release];
    [_participant release];
    [_participant_count release];
    [_wisher_count release];
    [_title release];
    [_cellActivityModel release];
    [super dealloc];
}

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        
        self.greenBackImageView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"bg_eventlistcell.png"]];
        [self.contentView addSubview:self.greenBackImageView];
        
        self.title = [[UILabel alloc]init];
        [self.greenBackImageView addSubview:self.title];
        
        self.whiteBackImageView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"bg_share_large.png"]];
        [self.greenBackImageView addSubview:self.whiteBackImageView];
        
        self.backImageView = [[UIImageView alloc]init];
        [self.whiteBackImageView addSubview:self.backImageView];
        
        self.line = [[UILabel alloc]init];
        self.line.text = @"--";
        [self.whiteBackImageView addSubview:self.line];
        
        self.timeImageView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"icon_date.png"]];
        [self.whiteBackImageView addSubview:self.timeImageView];
        
        self.locateImageView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"icon_spot.png"]];
        [self.whiteBackImageView addSubview:self.locateImageView];
        
        self.categoryImageView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"icon_catalog.png"]];
        [self.whiteBackImageView addSubview:self.categoryImageView];
        
        self.startTime = [[UILabel alloc]init];
        [self.whiteBackImageView addSubview:self.startTime];
        
        self.endTime = [[UILabel alloc]init];
        [self.whiteBackImageView addSubview:self.endTime];
        
        self.address = [[UILabel alloc]init];
        [self.whiteBackImageView addSubview:self.address];
        
        self.category_name = [[UILabel alloc]init];
        [self.whiteBackImageView addSubview:self.category_name];
        
        self.category = [[UILabel alloc]init];
        self.category.text = @"类型:";
        [self.whiteBackImageView addSubview:self.category];
        
        self.wisher = [[UILabel alloc]init];
        self.wisher.text = @"感兴趣:";
        [self.whiteBackImageView addSubview:self.wisher];
        
        self.participant = [[UILabel alloc]init];
        self.participant.text = @"参加:";
        [self.whiteBackImageView addSubview:self.participant];
        
        self.participant_count  = [[UILabel alloc]init];
        [self.whiteBackImageView addSubview:self.participant_count];
        
        self.wisher_count = [[UILabel alloc]init];
        [self.whiteBackImageView addSubview:self.wisher_count];
        
        [self.backImageView release];
        [self.title release];
        [self.wisher_count release];
        [self.participant_count release];
        [self.participant release];
        [self.wisher release];
        [self.category_name release];
        [self.address release];
        [self.endTime release];
        [self.startTime release];
        [self.whiteBackImageView release];
        [self.greenBackImageView release];
        [self.categoryImageView release];
        [self.locateImageView release];
        [self.timeImageView release];
 
    }
    return self;
}

-(void)layoutSubviews
{
    [super layoutSubviews];
    
    self.greenBackImageView.frame = CGRectMake(5, 5, kWith - 10, kHeight - 5);
    
    //
    self.title.frame = CGRectMake(5, 5, GREENSIZE.width, GREENSIZE.height * 0.2);
    self.whiteBackImageView.frame = CGRectMake(5, self.title.frame.size.height , GREENSIZE.width - 10, GREENSIZE.height * 0.75);
    
    //
    self.timeImageView.frame = CGRectMake(5, 5, 30, 30);
    self.startTime.frame = CGRectMake(40, 5, 100, 30);
    self.line.frame = CGRectMake(145, 5, 20, 30);
    self.endTime.frame = CGRectMake(170, 5, 270, 30);
    
    //
    self.locateImageView.frame = CGRectMake(5, 35, 30, 30);
    self.address.frame = CGRectMake(40, 35, WHITESIZE.width * 0.6, 30);
    
    //
    self.categoryImageView.frame = CGRectMake(5, 65, 30, 30);
    self.category.frame = CGRectMake(40, 65, WHITESIZE.width / 0.6, 30);
    self.category_name.frame = CGRectMake(90, 65, WHITESIZE.width / 3 * 2, 30);
    
    //
    self.wisher.frame = CGRectMake(10, 100, 60, 30);
    self.wisher_count.frame = CGRectMake(80, 100, 60, 30);
    
    self.participant.frame = CGRectMake(150, 100, 60, 30);
    self.participant_count.frame = CGRectMake(200, 100, 60, 30);
    
    
    
    
    
    //
    self.backImageView.frame = CGRectMake(GREENSIZE.width / 3 * 2 + 10, 5, WHITESIZE.width / 3 - 20, WHITESIZE.height - 10);
    

}



-(void)setCellActivityModel:(ActivityModel *)cellActivityModel
{
    if (_cellActivityModel != cellActivityModel) {
        [_cellActivityModel release];
        _cellActivityModel = [cellActivityModel retain];
    }
    
    NSURL *url = [NSURL URLWithString:cellActivityModel.image];
    
    NSData *data = [NSData dataWithContentsOfURL:url];
    
    UIImage *image = [UIImage imageWithData:data];
    
    self.backImageView.image = image;
    
        
    self.title.text = cellActivityModel.title;

    NSString *startTime = [cellActivityModel.begin_time substringWithRange:NSMakeRange(5, 11)];
    
    NSString *endTime = [cellActivityModel.end_time substringWithRange:NSMakeRange(5, 11)];
    
    self.endTime.text = endTime;
    
    self.startTime.text = startTime;
    
    self.wisher_count.text = [NSString stringWithFormat:@"%ld", cellActivityModel.wisher_count];
    
    self.participant_count.text = [NSString stringWithFormat:@"%ld", cellActivityModel.participant_count];
    
    self.category_name.text = cellActivityModel.category_name;
    
    self.address.text = cellActivityModel.address;
    
}


@end






















